<template>
	<view> 
		<view class="dd-head">
			<view  :class="asitemindex==item.status?'dd-sitem':'dd-item'" v-for="(item,index) in answer" :key="index" @tap="asitembtn(item)" >
				<text>{{item.name}}</text>
			</view>
		</view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption" height="0" style="min-height: 0;">
			<view class="voucher_list">
				<view class="voucher_list_item" v-for="(item,index) in list" :key="index" @tap="gotoWriteOffVoucherDetail(item)">
					<view class="voucher_list_item_top">
						<view class="voucher_list_item_top_left" :class="[item.type==3?'voucher_list_item_top_secondly':item.type==2?'voucher_list_item_top_thirdly':item.type==4&&'voucher_list_item_top_fourthly',asitemindex!=1&&'voucher_list_item_top_extra']">
							<view class="voucher_list_item_top_left_money">
								<text class="voucher_list_item_top_left_money_amount" :style="asitemindex!=0?'color:#fff':''">{{item.cancelType==0?'肥料券':item.cancelType==1?'参观券':'指导券'}}</text>
							</view>
							<text class="voucher_list_item_top_left_fullmoney" :style="asitemindex!=0?'color:#fff':''">共{{item.count}}张</text>
						</view>
						<view class="voucher_list_item_top_right">
							<view class="voucher_list_item_top_right_information">
								<view class="voucher_list_item_top_right_information_effect">
									<text class="voucher_list_item_top_right_information_effect_left" :class="[asitemindex!=0&&'voucher_list_item_top_right_information_effect_used']">{{item.name}}</text>
									<text v-if="item.type==3||item.type==4" class="voucher_list_item_top_right_information_effect_right" :class="[item.type==4&&'voucher_list_item_top_right_information_effect_vipright',asitemindex!=0&&'voucher_list_item_top_right_information_effect_used']">{{item.superimpose==1?'可叠加':'不可叠加'}}</text>
									<!-- <text v-if="item.type==4" class="voucher_list_item_top_right_information_effect_right voucher_list_item_top_right_information_effect_vipright" :class="[item.type==4&&'voucher_list_item_top_right_information_effect_vipright',asitemindex!=0&&'voucher_list_item_top_right_information_effect_used']">{{item.combination_id?'可组合':'不可组合'}}</text> -->
								</view>
								<view class="voucher_list_item_top_right_information_cxtravalue">
									<text class="voucher_list_item_top_right_information_time">有效期至 {{item.startTimeText}}</text>  
									<view class="voucher_list_item_top_right_boximage" v-if="asitemindex==1">
										<image src="@/static/my/used.png" mode=""></image>
									</view>
									<view class="voucher_list_item_top_right_boximage" v-if="asitemindex==3">
										<image src="@/static/my/stale.png" mode=""></image>
									</view>
								</view>  
							</view> 
						</view>
					</view>
					<view class="voucher_list_item_bottom">
						<view class="voucher_list_item_bottom_condition">
							<text class="voucher_list_item_bottom_condition_text" :class="[item.isImage&&'voucher_list_item_bottom_condition_extext']">
								{{item.useRule}}
							</text>
						</view>  
					</view>
				</view>
			</view>			
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"; 
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				asitemindex:0,
				answer:[{
						name: '未使用',
						status: 0,
					},
					{
						name: '已使用',
						status: 1
					},
					// {
					// 	name: '已分享',
					// 	status: 2
					// },
					{
						name: '已过期',
						status: 3
					}
				],
				// 下拉刷新的组件 参数 可以 改变的
				downOption: {
					use: false,
					auto: true //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					auto: true, // 不自动加载
					noMoreSize: 10, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '暂无核销券', // 提示
						icon: '/static/my/discounts_empty.png'
					},
					textNoMore: '—— 没有更多核销券了 ——'
				},
				list:[
				], 
				cateObj:{
					'1':'肥料券',
					'2':'参观券',
					'3':'指导券'
				}
			}
		},
		computed:{
			changList(){
				return function(item){
					if(item.isImage){
						return item.rulesList
					}else{
						let c=item.rulesList.filter((itemv,indexv)=>{
							return indexv==0
						})
						return c
					}
				}
			}
		},
		onShow() {
			this.upCallback({num:0,size:999999})
		},
		methods: {
			asitembtn(item){
				this.asitemindex=item.status
				this.list=[]
				// this.mescroll.resetUpScroll()
				this.upCallback({num:0,size:999999})
			},
			switchover(item){
				item.isImage=!item.isImage
			},
			//下拉刷新 不需要开启
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			// 跳转到首页
			goHome(){
				uni.switchTab({
					url:'/pages/home/home'
				})
			},
			// 上拉加载
			upCallback(page) {
			
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._postBody('user/coupon/lists', {
					dataType: self.asitemindex,
					pageIndex: page.num,
					pageSize: page.size,
					isHx: true, //是否核销
			
				}, function(res) {
					console.log(res);
					const { data } = res;
					let curPageLen = data.records.length;
					let totalPage = Number(data.total) / page.pageSize;
					if (page.num == 1) self.list = [];
					data.records.map(item => {
						item.isImage = false
						return item
					})
					self.list = data.records;
					self.mescroll.endByPage(curPageLen, totalPage)
				});
			},
			gotoWriteOffVoucherDetail(item) {
				console.log(item,111)
				if(this.asitemindex == 0) {
					let name = this.cateObj[item.cate]; 
					let voucherDetailObj = JSON.stringify(item); 
					uni.navigateTo({
						url:`/userpage/userinfo/walletDetail/writeOffVoucherDetail?name=核销${name}&voucherDetailObj=${voucherDetailObj}`
					})
				} 
			}
		}
	}
</script>
<style scoped>
	/deep/.empty-icon{
		margin: 0 auto;
	}
</style>
<style lang="less" scoped>
	.dd-head{
		display: flex;
		justify-content: space-between;
		padding: 0rpx 54rpx;
		line-height: 84rpx;
		border-bottom: 1px solid rgba(238,238,238,1);
		z-index: 99;
		position: sticky;
		top: var(--window-top);
		position: -webkit-sticky;
		background: #FFFFFF;
	}
	.dd-sitem{
		font-size:34rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight:500;
		line-height: 84rpx;
		color:#077840;
		border-bottom: 4rpx solid #077840;
	}
	.dd-item{
		font-size: 34rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		line-height: 84rpx;
	} 
	.voucher_list{
		padding:0 30rpx;   
		position: relative;
		align-items: center;
		justify-content: center;
		display: flex;
		flex-direction: column;
		// &_item::before{
		// 	    content: ' '; 
		// 		width:18rpx;
		// 		height: 36rpx;  
		// 		background: #D8D8D8;
		// 		opacity: 0.2;
		// 		border-radius: 0 18rpx 18rpx 0;
		// 	    position: absolute;  
		// 	    top: 166rpx;
		// 	    left: 0;    
		// 		opacity: 0.2; 
		// }  
		// &::after{   
		// 		 content: '';
		// 		    position: absolute;
		// 		    height: 100%;
		// 		    width:10px;
		// 		    top: 0;
		// 		    right: -10px;
		// 		    background-image: linear-gradient(to bottom, #fff 10px, transparent 10px, transparent),
		// 		    radial-gradient(20px circle at 10px 20px, transparent 10px, #fff 10px);
		// 		    background-size: 10px 30px;  
		// }
		&_item{ 
			padding: 0 20rpx;
			margin-top: 30rpx;
			box-shadow: 0px 0px 40rpx 4px rgba(91, 74, 40, 0.1);
			border-radius: 8rpx; 
			background-color: #fff;
			width: calc(100% - 60rpx);
			position: relative;
			&::before {
			    content: '';
			    position: absolute;
			    height: 100%;
			    width: 8px;
			    right: -8px;
			    top: 0;
			    background-image: radial-gradient(circle at 8px 10px, transparent 6px, white 6px);
			    background-size: 8px 26px;
			}
			&::after {
				content: '';
				position: absolute;
				height: 100%;
				width: 8px;
				left: -8px;
				top: 0;
				background-image: radial-gradient(circle at 0px 10px, transparent 6px, white 6px);
				background-size: 8px 26px;
			}
			&_dott {
				width:36rpx;
				height: 18rpx;  
				background: #D8D8D8; 
				border-radius:0 0 18rpx 18rpx;
				opacity: 0.2;
				position: absolute;  
				top: 0;
				left: 180rpx;    
			}
			&_bottomdott {
				width:36rpx;
				height: 18rpx;  
				background: #D8D8D8; 
				border-radius:18rpx 18rpx 0 0;
				opacity: 0.2;
				position: absolute;  
				bottom: 0;
				left: 180rpx;    
			} 
			&_top{
				padding: 24rpx 0;
				display: flex;
				align-items: flex-start;
				&_left{
					width: 200rpx;
					height: 150rpx;
					background: linear-gradient(315deg, #F6E3B8 0%, #DAB279 100%);
					border-radius: 12rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					margin-right: 20rpx;
					&_money{
						display: flex;
						align-items: center;
						&_sign{
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
							line-height: 34rpx;
							margin-top: 30rpx;
						}
						&_amount{
							font-size: 48rpx;
							font-family: PingFangSC-Medium, PingFang SC;
							font-weight: 500;
							color: #735116;
							line-height: 84rpx;
						}
					}
					&_fullmoney{
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #735116;
						line-height: 34rpx;
					}
				}
				&_secondly{
					background: linear-gradient(90deg, #FF9800 0%, #FF4E00 100%);
				}
				&_thirdly{
					background: linear-gradient(90deg, #5BB6FB 0%, #2F80F6 100%);
				}
				&_fourthly{
					background: linear-gradient(315deg, #F6E3B8 0%, #DAB279 100%);
					.voucher_list_item_top_left_money_sign{
						color: #735116;
					}
					.voucher_list_item_top_left_money_amount{
						color: #735116;
					}
					.voucher_list_item_top_left_fullmoney{
						color: #735116;
					}
				}
				&_extra{
					background: #C8C8C8;
				}
				&_right{
					display: flex;
					// justify-content: space-between;
					// align-items: center;
					flex: 1;
					min-height: 152rpx;
					&_information{
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						&_effect{
							display: flex;
							align-items: flex-start;
							&_left{
								flex: 1;
								font-size: 30rpx;
								font-family: PingFangSC-Medium, PingFang SC;
								font-weight: 500;
								color: #333333;
								line-height: 40rpx;
								margin-right: 8rpx;
							}
							&_right{
								width: 98rpx;
								height: 32rpx;
								background: #FFFFFF;
								border-radius: 4rpx;
								border: 2rpx solid #FF5100;
								font-size: 20rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #FF5100;
								line-height: 28rpx;
								text-align: center;
								box-sizing: border-box;
								margin-top: 4rpx;
							}
							&_vipright{
								margin-left: 16rpx;
							}
							&_used{
								border-color:#C8C8C8;
								color: #C8C8C8;
							}
							&_vipright{
								border-color:#735116;
								color: #735116;
							}
							&_stale{
								background-color: #C8C8C8;
							}
						}
						&_cxtravalue{
							display: flex;
							align-items: center;
							justify-content: space-between;
						}
						&_time{
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							line-height: 34rpx;
						}
						&_amount{
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							line-height: 34rpx;
						}
						&_used{
							color: #999999;
						}
						&_stale{
							color: #999999;
						}
					}
					&_status{
						display: flex;
						align-items: center;
						&_text{
							width: 124rpx;
							height: 48rpx;
							background: #FFFFFF;
							border-radius: 26rpx;
							border: 2rpx solid #077840;
							font-size: 22rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #077840;
							line-height: 44rpx;
							text-align: center;
							box-sizing: border-box;
						}
						&_secondly{
							border: 2rpx solid #FF5100;
							color: #FF5100;
						}
						&_thirly{
							border: 2rpx solid #2F80F6;
							color: #2F80F6;
						}
						&_fourthly{
							border: 2rpx solid #242C3B;
							color: #242C3B;
						}
					}
					&_boximage{
						width: 136rpx;
						display: flex;
						align-items: center;
						image{
							width: 136rpx;
							height: 114rpx;
							vertical-align: top;
						}
					}
				}
			}
			&_bottom{
				padding: 24rpx 0;
				border-top: 2rpx dashed #E5E5E5;
				display: flex;
				justify-content: space-between;
				&_condition{
					display: flex;
					flex-direction: column;
					width: calc( 100% - 50rpx );
					&_text{
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						line-height: 34rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
					&_extext{
						overflow:inherit;
						text-overflow: inherit;
						white-space: inherit;
					}
				}
				&_imageview{
					height: 34rpx;
					width: 44rpx;
					margin-right: -10rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				&_image{
					width: 24rpx;
					height: 14rpx;
					vertical-align: top;
					// margin-top: 10rpx;
					// margin-left: 24rpx;
					transform: rotate(0);
					// transition: 0.3s ease-in-out;
				}
				&_eximage{
					transform: rotate(-180deg);
				}
			}
		}
	}

</style>
